#include "graph.h"
#include <bits/stdc++.h> 

using namespace std;

const int N = 205;
int n;
int dis[N][N], ans[N], deg[N], tree[N][N], prt[N];
vector<int> a[N], b[N], path, back_path; 
vector<int> vec[N][N];

void dfs(int u) {
	a[u] = path, b[u] = back_path; 
	deg[u] = NumberOfRoads();
	for (int i = 1; i <= deg[u]; i++) {
		Move(i, 2);
		if (Color() == 1) {
			int v = ++n, las = LastRoad();
			tree[u][i] = v, tree[v][las] = u, prt[v] = las;
			dis[u][v] = dis[v][u] = 1;
			path.emplace_back(i);
			back_path.emplace_back(las);
			dfs(v);
			Move(las, 2);
			path.pop_back();
			back_path.pop_back(); 
		} else {
			vec[LastRoad()][i].emplace_back(u);
			Move(LastRoad(), 2); 
		}
	}
}

bool run(vector<int> vec) {
	for (auto i : vec) {
		int c = Color();
		Move(i, c);
	}
}

int getIdx(int u, int i, int las) {
	int ret = 0;
	run(b[u]);
	for (auto x : vec[i][las]) {
		run(a[x]);
		if (las > deg[x]) {
			run(b[x]);
			continue;
		}
		Move(las, Color());
		if (Color() == 3) {
			ret = x;
		} 
		Move(LastRoad(), Color());
		run(b[x]);
		if (ret != 0) break;
	} 
	run(a[u]);
	return ret;
}

void build(int u) {
	for (int i = 1; i <= deg[u]; i++) if (!tree[u][i]) {
		Move(i, 3);
		int las = LastRoad();
		Move(las, 2);
		int v = getIdx(u, i, las);
		dis[u][v] = dis[v][u] = 1;
	}
	for (int i = 1; i <= deg[u]; i++) if (tree[u][i] && i != prt[u]) {
		Move(i, 2);
		int las = LastRoad();
		build(tree[u][i]);
		Move(las, 2);
	}
}

void Inspect(int R) {
	n++, dfs(n);

	for (int i = 1; i <= n; i++) reverse(b[i].begin(), b[i].end());

	build(1);
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) if (i != j) {
			if (!dis[i][j]) dis[i][j] = R + 1;
		}
	}
	
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (dis[i][j] <= R) ans[dis[i][j]]++;
		}
	} 

	for (int i = 1; i <= R; i++) Answer(i, ans[i]);
}
